package org.springblade.core.license;

import de.schlichtherle.license.LicenseContent;
import de.schlichtherle.license.LicenseManager;
import de.schlichtherle.license.LicenseParam;

import java.util.Optional;

/**
 * de.schlichtherle.license.LicenseManager的单例
 *
 * @author zifangsky
 * @date 2018/4/19
 * @since 1.0.0
 */
public class LicenseManagerHolder {

    private static volatile LicenseManager LICENSE_MANAGER;

    private static LicenseContent content = null;

    public static LicenseManager getInstance(LicenseParam param) {
        if (LICENSE_MANAGER == null) {
            synchronized (LicenseManagerHolder.class) {
                if (LICENSE_MANAGER == null) {
                    LICENSE_MANAGER = new CustomLicenseManager(param);
                }
            }
        }
        return LICENSE_MANAGER;
    }

    public static void setLicenseContent(LicenseContent content) {
        LicenseManagerHolder.content = content;
    }

    public static Optional<LicenseContent> getLicenseContent() {
        return Optional.ofNullable(content);
    }


}
